<?

class Prodotto extends StdClass
{
	var $id_negozio;
	var $db;
		
	function Prodotto($id_negozio, $id_prodotto, &$db, $row = null, $varianti = null)
	{

		
		$this->id_negozio = $id_negozio;
		$this->percorso = $percorso;
		$this->db = &$db;
		
		if(! is_object($row))
		{
			$query = "SELECT * FROM moka_ecomm_$this->id_negozio.prodotti WHERE id='$id_prodotto' ";	
			$result = $this->db->query($query);
			if(mysql_num_rows($result) > 0)
			{
				$row = mysql_fetch_object($result);	
			}
		}
		// CARICO DATI
		$this->load_prod($row);
		//CARICO VARIANTI
		$this->load_varianti($varianti);
		// CARICO PREZZI
		$this->load_prices();
			
	}
	
	function load_prod($row)
	{
		
		
			$this->id 			= $row->id ;
			$this->id_categoria = $row->id_categoria ;
			if(!$this->id_categoria) $this->id_categoria = $_REQUEST[id_categoria];
			$this->categoria	= $GLOBALS[cat_struct][categorie][$row->id_categoria];
			//print_r($GLOBALS[cat_struct]);
			//echo "##$row->id_categoria#";
			$this->nome 		= $row->{'nome_'.$_SESSION[lingua]};
			$this->descrizione 	= $row->{'descrizione_'.$_SESSION[lingua]};
			$this->nome_ita 		= $row->nome_ita;
			$this->descrizione_ita 	= $row->descrizione_ita;
			$this->nome_eng 		= $row->nome_eng;
			$this->descrizione_eng 	= $row->descrizione_eng;
/*DEVO CAPIRE COME RECUPERARE PERCORSO DEL PRODOTTO*/			
			$this->{'file'} 	= $this->categoria[percorso].'/'.$row->{'file_'.$_SESSION[lingua]};
			$this->file_ita 	= $row->file_ita;
			$this->file_eng 	= $row->file_eng;
			//$this->prezzo 		= $row->prezzo;
			$this->iva 			= $row->iva;
			$this->ordine 		= $row->ordine;
			$this->id_variante_1= $row->id_variante_1;
			$this->id_variante_2= $row->id_variante_2;
			$this->varianti[0] = array();
			$this->varianti[$row->id_variante_1] = array();
			$this->varianti[$row->id_variante_2] = array();
	}
	
	function load_immagini()
	{
		$query = "SELECT * FROM moka_ecomm_$this->id_negozio.prodotti_immagini 					
				WHERE id_prodotto='$this->id' ORDER BY ordine";	
			$result = $this->db->query($query);
			$n = 0;
			if(!$result)echo $query;
			while($rw = mysql_fetch_assoc($result))
			{
				$this->immagini[] = $rw[nome_file];
			}
			//print_r($this->immagini);
	}
	
	function load_varianti($varianti)
	{
		// CARICO VARIANTI
		if(!is_array($varianti))
		{
			$query = "SELECT varianti.id, varianti.nome_ita as nome_var, prodotti_varianti_valori.valore, prodotti_varianti_valori.nome_file,  prodotti_varianti_valori.nome_ita , prodotti_varianti_valori.nome_eng , prodotti_varianti_valori.incremento, prodotti_varianti_valori.default 
			FROM moka_ecomm_$this->id_negozio.varianti 					
					INNER JOIN moka_ecomm_$this->id_negozio.prodotti_varianti_valori ON varianti.id = prodotti_varianti_valori.id_variante 		
					WHERE prodotti_varianti_valori.id_prodotto='$this->id' ";	
			$result = $this->db->query($query);
			$n = 0;
			if(!$result)echo $query;
			while($rw = mysql_fetch_assoc($result))
			{
				$this->varianti[$rw[id]][valori][$rw[valore]][ita] = $rw['nome_ita'];	
				$this->varianti[$rw[id]][valori][$rw[valore]][eng] = $rw['nome_eng'];	
				$this->varianti[$rw[id]][nome_file][$rw[valore]] = $rw['nome_file'];		
				//$this->varianti[$rw[id]][incrementi][$rw[valore]] = $rw[incremento];			
				$this->varianti[$rw[id]][nome_var] = $rw[nome_var];		
				if($rw['default']>0)
				{ 
					$this->varianti[$rw[id]]['selected'] = $rw[valore];
				}
			}
		}else
		{
			$this->varianti = $varianti;
		}
		
	}
	
	function load_prices()
	{
		/// CARICO I PREZZI
		$this->prezzi = array();
		$this->quantita = array();
		$query = "SELECT *  
				FROM moka_ecomm_$this->id_negozio.prodotti_prezzi_quant 
				WHERE prodotti_prezzi_quant.id_prodotto='$this->id' ";	
		$result = $this->db->query($query);
		if(!$result)echo $query;
		while($rw = mysql_fetch_assoc($result))
		{
			$this->prezzi[$rw[valore_1]][$rw[valore_2]] = number_format($rw[prezzo], $_SESSION[configurazione][n_decimali],"."," ");	
			$this->quantita[$rw[valore_1]][$rw[valore_2]] = $rw[quantita];	
			
		}

		$this->prezzo = number_format($this->prezzi[$this->varianti[$this->id_variante_1]['selected']][$this->varianti[$this->id_variante_2]['selected']], $_SESSION[configurazione][n_decimali],"."," ");
	}
	
	function get_price($valore_var_1="0", $valore_var_2="0")
	{
		//echo "#-- $valore_var_1 $valore_var_2 --#";
		global $lang;
		$prezzo = 0.00;
		if(count($this->varianti)>0 )
		{ 
			if($valore_var_1=="0" && $valore_var_2=="0")
			{
				// CERCO VALORI DI DEFAULT
				//echo " $this->id_variante_1 $this->id_variante_2 sel:".$this->varianti[$this->id_variante_1][selected];
				$def_v1 = $this->varianti[$this->id_variante_1][selected];
				$def_v2 = $this->varianti[$this->id_variante_2][selected];
				if(!(strlen($def_v1)>0))$def_v1 = 0;
				if(!(strlen($def_v2)>0))$def_v2 = 0;
				$prezzo = $this->prezzi[$def_v1][$def_v2] ;
				//print_r($this->prezzi);
			}else
			{
				$prezzo = $this->prezzi[$valore_var_1][$valore_var_2];
				
			}
		}else
		{
			// SE NON HA VARIANTI RITORNO SEMPLICEMENTE PREZZO
			$prezzo = $this->prezzi[0][0];
			
		}
		
		return $prezzo;
	}
	
	function get_form()
	{
		global $lang;
		$html = "
<form id='form1' name='form1' method='get' action=''>
	".$this->get_varianti()."
  <br>
  <label>".__('quantità')."
  <input name='quantita' type='text' id='quantita' value='1' size='3' maxlength='5' />
  </label>
  <input type='submit' name='Submit' value='"._s('aggiungi al carrello')."' /><br/>
  <a href='/carrello'>".__('vedi il carrello')."</a>
  <input type='hidden' name='mod' value='add'/>
  
</form>";
		return $html;
	}
	
	function get_varianti($tipo="select")
	{
		$ret = "";
		$n = 0;
		if(is_array($this->varianti))
		{
			foreach($this->varianti as $idv=>$arv)if($arv[valori])
			{
				if($tipo=="select")
				{
					$ret .= "\n<label>".$arv["nome_var"]." <br>
		  					<select id=\"variante_$n\" name='varianti[$n][valore]'>\n";
		  			foreach($arv[valori] as $val=>$nome_val)
		  			{			
		  				if($arv[selected] == $val) $sel = 'selected';
		  				else $sel = '';
		  				
		  				$ret .= "<option value=\"$val\" $sel>".$nome_val[$_SESSION[lingua]]."</option>\n";		
		  			}
		  			$ret .=	"
		  					</select>\n
		  					<input type='hidden' name='varianti[$n][id]' value='$idv'/>\n
		  					</label>\n<br>";
				}
				elseif($tipo=="hidden")
				{
					$ret .= "\n	<input type=\"hidden\" id=\"variante_$n\" name='varianti[$n][valore]' value='$arv[selected]'>
								<input type=\"hidden\" id=\"varid_$n\" name='varianti[$n][id]' value='$idv'>	";
				}
	  				
	  			$n++;
			}
		}
		return $ret;
	}
	
	function get_immagini()
	{
		if(!is_array($this->immagini))$this->load_immagini();
		return $this->immagini;
	}
	
	function Save()
	{
		if(!($this->id)>0)
		{
			// SE NUOVO AGGIUNGO
			$query = "INSERT INTO moka_ecomm_$this->id_negozio.prodotti SET nome_ita = \"".$_REQUEST[nome_ita]."\" ";
			$this->db->query($query);
			$this->id = mysql_insert_id();
			if(mysql_error())echo $query." -- ".mysql_error();

		}
		
		// SALVO
		$query = "UPDATE moka_ecomm_$this->id_negozio.prodotti SET 
			nome_ita = \"".$_REQUEST[nome_ita]."\",
			descrizione_ita = \"".$_REQUEST[descrizione_ita]."\",
			file_ita = \"".$_REQUEST[file_ita]."\",
			nome_eng = \"".$_REQUEST[nome_eng]."\",
			descrizione_eng = \"".$_REQUEST[descrizione_eng]."\",
			file_eng = \"".$_REQUEST[file_eng]."\",
			id_categoria = \"".(0+$_REQUEST[id_categoria])."\",
			ordine =  \"".(0+$_REQUEST[ordine])."\",
			id_variante_1 = \"".(0+$_REQUEST[id_variante_1])."\",
			id_variante_2 = \"".(0+$_REQUEST[id_variante_2])."\"
			WHERE id='".$this->id."'";
		$this->db->query($query);
		if(mysql_error())echo $query." -- ".mysql_error();
		
		
		for($i=1;$i<=2;$i++)
		{
			// SE CAMBIATO VARIANTE
			if( $_REQUEST["id_variante_$i"] != $this->{"id_variante_$i"} )
			{
				$query = "DELETE FROM moka_ecomm_$this->id_negozio.prodotti_varianti_valori WHERE id_prodotto=\"$this->id\" AND id_variante=\"".$this->{"id_variante_$i"}."\"";
				$this->db->query($query);
				if(mysql_error())echo $query." -- ".mysql_error();
			}
			
			/*// CARICO VALORI DI QUESTA VARIANTE
			$query = "SELECT * FROM moka_ecomm_$this->id_negozio.prodotti_varianti_valori WHERE id_prodotto=\"$this->id\" AND id_variante=\"".$this->{"id_variante_$i"}."\"";
			$rs = $this->db->query($query);
			if(mysql_error())echo $query." -- ".mysql_error();
			$db_valori = array();
			while($rw = mysql_fetch_object($rs))
			{
				$db_valori[$rw->id_variante][$rw->valore] = true;
			}*/
			
			// POI RISALVO O INSERISCO QUELLE NUOVE
			$var_valore = "var_".$i."_valore";
			$var_etichetta_ita = "var_".$i."_etichetta_ita";
			$var_etichetta_eng = "var_".$i."_etichetta_eng";
			$var_default = "var_".$i."_default";
			$var_file = "img_var_".$i."_val_";
			$lista_valori = "'null',";
			
			if(is_array($_REQUEST[$var_valore]))foreach($_REQUEST[$var_valore] as $n => $valore)
			{
				// CARICO IMMAGINE
				$ilmiofile = $_FILES[$var_file.$n];
				$handle = new Upload($ilmiofile);
				//print_r($ilmiofile);
					
				$img_fs_path = FS_K_SHOP.$_SERVER[SERVER_NAME]."/var/";
				//echo "SCRIVO IN: $img_fs_path";
				
				$file_destinazione = "";
				$uploaded = false;
				if ($handle->uploaded) {
					/*if(file_exists($img_fs_path."S/".$n)&&strlen($n)>0)
					{
						unlink($img_fs_path.$n);
						@unlink($img_fs_path."S/".$n);
						@unlink($img_fs_path."M/".$n);
						@unlink($img_fs_path."L/".$n);
					}*/
					
					$tipo_med = split("/",$file[type]);
					if(!strlen($filename)>0)$img_fs_path = $img_fs_path;
					if(!file_exists($img_fs_path))
					{	mkdir($img_fs_path);
					}
					
					if(!file_exists($img_fs_path."S/"))
					{	mkdir($img_fs_path."S/");
					}if(!file_exists($img_fs_path."M/"))
					{	mkdir($img_fs_path."M/");
					}if(!file_exists($img_fs_path."L/"))
					{	mkdir($img_fs_path."L/");
					}
					// yes, the file is on the server
					// below are some example settings which can be used if the uploaded file is an image.
		
					// echo "X:".$handle->image_x  ;
					//echo "Y:".$handle->image_y  ;
					///// LARGE
					$handle->image_resize          = true;
					$handle->image_ratio           = true;
					$handle->image_ratio_crop		= ($_SESSION[configurazione][crop_L])?true:false;
					$handle->image_y               = $_SESSION[configurazione][img_L_height];
					$handle->image_x               = $_SESSION[configurazione][img_L_width];
					
		
					//echo "X:".$handle->image_x  ;
					//echo "Y:".$handle->image_y  ;
		
		
					// now, we start the upload 'process'. That is, to copy the uploaded file
					// from its temporary location to the wanted location
					// It could be something like $handle->Process('/home/www/my_uploads/');
					$handle->Process($img_fs_path."L/");
		
					// we check if everything went OK
					if ($handle->processed) {
						// everything was fine ! //echo '<fieldset>'; //echo '  <legend>file uploaded with success</legend>'; //echo '  <img src="test/' . $handle->file_dst_name . '" />';
						$info = getimagesize($handle->file_dst_pathname); //echo '  <p>' . $info['mime'] . ' &nbsp;-&nbsp; ' . $info[0] . ' x ' . $info[1] .' &nbsp;-&nbsp; ' . round(filesize($handle->file_dst_pathname)/256)/4 . 'KB</p>'; //echo '  link to the file just uploaded: <a href="test/' . $handle->file_dst_name . '">' . $handle->file_dst_name . '</a><br/>'; //echo '</fieldset>';
					} else {
						// one error occured //echo '<fieldset>'; //echo '  <legend>file not uploaded to the wanted location</legend>'; //echo '  Error: ' . $handle->error . ''; //echo '</fieldset>';
					}
					///// MEDIA
					// we now process the image a second time, with some other settings
					$handle->image_resize          = true;
					$handle->image_ratio           = true;
					$handle->image_ratio_crop		= ($config[crop_M])?true:false;
					$handle->image_y               = $_SESSION[configurazione][img_M_height];
					$handle->image_x               = $_SESSION[configurazione][img_M_width];
					//$img_fs_path = ROOT_SITI.$_SESSION[navigazione][nome_dir]."/media_$tipo_med[0]/med/";
		
					$handle->Process($img_fs_path."M/");
		
					// we check if everything went OK
					if ($handle->processed) {
						// everything was fine ! //echo '<fieldset>'; //echo '  <legend>file uploaded with success</legend>'; //echo '  <img src="test/' . $handle->file_dst_name . '" />';
						$info = getimagesize($handle->file_dst_pathname); //echo '  <p>' . $info['mime'] . ' &nbsp;-&nbsp; ' . $info[0] . ' x ' . $info[1] .' &nbsp;-&nbsp; ' . round(filesize($handle->file_dst_pathname)/256)/4 . 'KB</p>'; //echo '  link to the file just uploaded: <a href="test/' . $handle->file_dst_name . '">' . $handle->file_dst_name . '</a><br/>'; //echo '</fieldset>';
					} else {
						// one error occured //echo '<fieldset>'; //echo '  <legend>file not uploaded to the wanted location</legend>'; //echo '  Error: ' . $handle->error . ''; //echo '</fieldset>';
					}
		
		
					///// S
					// we now process the image a second time, with some other settings
					$handle->image_resize          = true;
					$handle->image_ratio           = true;
					$handle->image_ratio_crop		= ($config[crop_S])?true:false;
					$handle->image_y               = $_SESSION[configurazione][img_S_height];
					$handle->image_x               = $_SESSION[configurazione][img_S_width];
					//$img_fs_path = ROOT_SITI.$_SESSION[navigazione][nome_dir]."/media_$tipo_med[0]/thumb/";
		
					$handle->Process($img_fs_path."S/");
		
					// we check if everything went OK
					if ($handle->processed) {
						// everything was fine ! //
						//echo '<fieldset>'; //echo '  <legend>file uploaded with success</legend>'; //echo '  <img src="test/' . $handle->file_dst_name . '" />';
						$info = getimagesize($handle->file_dst_pathname);
						$file_destinazione = $handle->file_dst_name;
						$uploaded = true;
						 //
						//echo '  <p><img align="left" src="/img/S/' . $handle->file_dst_name . '">' . $info['mime'] . ' &nbsp;-&nbsp; ' . $info[0] . ' x ' . $info[1] .' &nbsp;-&nbsp; ' . round(filesize($handle->file_dst_pathname)/256)/4 . 'KB<br/>'; //
						//echo '  ' . $handle->file_dst_name.'</p>' ; //
						//echo '</fieldset>';
					} else {
						// one error occured //echo '<fieldset>'; //echo '  <legend>file not uploaded to the wanted location</legend>'; //echo '  Error: ' . $handle->error . ''; //echo '</fieldset>';
					}
					// we delete the temporary files
					$handle-> Clean();	
						
		
				} else {
					// if we're here, the upload file failed for some reasons
					// i.e. the server didn't receive the file
					$uploaded = false;
					$file_destinazione = "";
				}
					
				
				// SALVO DATI IN DB
				$var_default_val = 0;
				if($_REQUEST[$var_default] == $n)$var_default_val = 1;
				$qpiece = " nome_file = \"".$_REQUEST[$var_file.$n]."\", ";
				if($uploaded) $qpiece = " nome_file = \"$file_destinazione\", ";
				$query = "REPLACE INTO moka_ecomm_$this->id_negozio.prodotti_varianti_valori SET 
						id_prodotto=\"$this->id\" , 
						id_variante=\"".$_REQUEST["id_variante_$i"]."\" , 
						valore=\"$valore\" , 
						nome_ita = \"".$_REQUEST[$var_etichetta_ita][$n]."\",
						nome_eng = \"".$_REQUEST[$var_etichetta_eng][$n]."\",
						$qpiece
						`default` = \"$var_default_val\"						
						";
						$this->db->query($query);
						if(mysql_error())echo $query." -- ".mysql_error();
						
						$lista_valori .= "'$valore',";
			}
			$lista_valori = substr($lista_valori,0,-1);
			
			// ORA CANCELLO QUELLI NON + PRESENTI
			$query = "DELETE FROM moka_ecomm_$this->id_negozio.prodotti_varianti_valori WHERE id_prodotto=\"$this->id\" AND id_variante=\"".$_REQUEST["id_variante_$i"]."\" AND valore NOT IN ($lista_valori)";
			$this->db->query($query);
			if(mysql_error())echo $query." -- ".mysql_error();
			
			
				
		}
		
		
		// RIORDINO
		$query = "SELECT * FROM moka_ecomm_$this->id_negozio.prodotti WHERE id_categoria='".(0+$_REQUEST[id_categoria])."' ORDER BY ordine ";	
		$result = $this->db->query($query);
		$n = 1;
		while($row = mysql_fetch_object($result))
		{
			
			$query = "UPDATE moka_ecomm_$this->id_negozio.prodotti SET ordine =  \"".$n."\" WHERE id='".$row->id."'";
			$ru = $this->db->query($query);
			if(mysql_error())echo $query." -- ".mysql_error();
			$n += 2;
			
		}
		
		// SALVO ANAGRAFICHE AGGIUNTIVE
		$anagrafiche = $this->getAnagrafica();
		foreach($anagrafiche as $ida=>$campo)
		{
			
			$query = "REPLACE INTO moka_ecomm_$this->id_negozio.prodotti_anagr_val 
					SET id_prodotto='".$this->id."', 
					nome_campo='$campo[nome]',  
					valore = '".$_REQUEST[anagr][$campo[nome]]."' 				
					";
			$this->db->query($query);
			
		}
		
		
		
		
		// RIGENERO DATI QUESTA CATEGORIA
		$this->Prodotto($this->id_negozio, $this->id, &$this->db);
		
		

	}
	
	
	function get_ordine_options()
	{
		if($this->id>0)
		{
			$query = "SELECT id ,ordine, nome_ita FROM moka_ecomm_$this->id_negozio.prodotti WHERE id_categoria IN (SELECT id_categoria FROM moka_ecomm_$this->id_negozio.prodotti WHERE id='$this->id') ";	
			$result = $this->db->query($query);
			$out = "\n<option value=\"0\" >Inizio</option>";
			while($row = mysql_fetch_object($result) )
			{
				$sel = ""; if($row->ordine==($this->ordine-2)){$sel = "selected"; }
				if($row->id!=$this->id)$out .= "\n<option value=\"".(1+$row->ordine)."\" $sel >Dopo ".$row->nome_ita."</option>";	
			}
		}else 
		{
			$out = "\n<option value=\"999\" >Ultimo</option>";
		}
		return $out;
	}
	
	function SavePrices()
	{
		// CANCELLO TUTTO IL VECCHIO
		$query = "DELETE FROM moka_ecomm_$this->id_negozio.prodotti_prezzi_quant WHERE id_prodotto=\"$this->id\"";
		$rd = $this->db->query($query);
		if(mysql_error())echo $query." -- ".mysql_error();
		// RICREO NUOVO
		if(count($this->varianti)>1)
		{
			if(count($this->varianti)==3)
			{
				if(is_array($this->varianti[$this->id_variante_1][valori]))foreach($this->varianti[$this->id_variante_1][valori] as $valore_A=>$etichetta_A)
				if(is_array($this->varianti[$this->id_variante_2][valori]))foreach($this->varianti[$this->id_variante_2][valori] as $valore_B=>$etichetta_B)
				{
					$query = "REPLACE INTO moka_ecomm_$this->id_negozio.prodotti_prezzi_quant SET
								id_prodotto=\"$this->id\",
								id_variante_1=\"$this->id_variante_1\",
								id_variante_2=\"$this->id_variante_2\",
								valore_1=\"$valore_A\",
								valore_2=\"$valore_B\",
								prezzo=\"".(0+$_REQUEST["prezzo"][$valore_A][$valore_B])."\",
								quantita=\"".(0+$_REQUEST["quantita"][$valore_A][$valore_B])."\"
								";
					$ru = $this->db->query($query);
					if(mysql_error())echo $query." -- ".mysql_error();
					
				}
			}elseif(count($this->varianti)==2)
			{
				if(is_array($this->varianti[$this->id_variante_1][valori]))foreach($this->varianti[$this->id_variante_1][valori] as $valore_A=>$etichetta_A)
				{
					$query = "REPLACE INTO moka_ecomm_$this->id_negozio.prodotti_prezzi_quant SET
								id_prodotto=\"$this->id\",
								id_variante_1=\"$this->id_variante_1\",
								id_variante_2=\"0\",
								valore_1=\"$valore_A\",
								valore_2=\"0\",
								prezzo=\"".(0+$_REQUEST["prezzo"][$valore_A][0])."\",
								quantita=\"".(0+$_REQUEST["quantita"][$valore_A][0])."\"
								";
					$ru = $this->db->query($query);
					if(mysql_error())echo $query." -- ".mysql_error();
					
				}
			}
			
		}else {
			$query = "REPLACE INTO moka_ecomm_$this->id_negozio.prodotti_prezzi_quant SET
							id_prodotto=\"$this->id\",
							id_variante_1=\"0\",
							id_variante_2=\"0\",
							valore_1=\"0\",
							valore_2=\"0\",
							prezzo=\"".(0+$_REQUEST["prezzo"][0][0])."\",
							quantita=\"".(0+$_REQUEST["quantita"][0][0])."\"
							";
			$ru = $this->db->query($query);
			if(mysql_error())echo $query." -- ".mysql_error();
		}
		$this->load_prices();
	}
	
	public function getAnagrafica()
	{
		$anagrafiche = array();
		$query = "SELECT * FROM moka_ecomm_$this->id_negozio.prodotti_anagrafiche 
					LEFT JOIN  moka_ecomm_$this->id_negozio.prodotti ON prodotti_anagrafiche.id_categoria = prodotti.id_categoria	
					LEFT JOIN moka_ecomm_$this->id_negozio.prodotti_anagr_val ON prodotti_anagrafiche.nome = prodotti_anagr_val.nome_campo  AND prodotti_anagr_val.id_prodotto='".$this->id."'				
					WHERE prodotti.id='".$this->id."'   ORDER BY prodotti_anagrafiche.ordine ";	
		$result = $this->db->query($query);
		$n = 1;
		//echo $query;
		while($row = mysql_fetch_object($result))
		{
			$anagrafiche[$row->id][id] = $row->id;
			$anagrafiche[$row->id][nome] = $row->nome;
			$anagrafiche[$row->id][etichetta] = $row->etichetta;
			$anagrafiche[$row->id][tipo] = $row->tipo;
			$anagrafiche[$row->id][ordine] = $row->ordine;
			$anagrafiche[$row->id][valore] = $row->valore;
			
		}
		//print_r($anagrafiche);
		return $anagrafiche;
	} 
	
	function Delete()
	{
		if($this->id>0)
		{
			// CANCELLO TUTTE LE VARIANTI
			$query = "DELETE FROM moka_ecomm_$this->id_negozio.prodotti_varianti_valori WHERE id_prodotto='".$this->id."'";
			$rd = $this->db->query($query);
			if(mysql_error())echo $query." -- ".mysql_error();
			
			// CANCELLO PRODOTTO
			$query = "DELETE FROM moka_ecomm_$this->id_negozio.prodotti WHERE id='".$this->id."'";
			$rd = $this->db->query($query);
			if(mysql_error())echo $query." -- ".mysql_error();
			
			
		}
	}

}
?>